Conversation
WalkthroughThis update refactors the email composer to fetch aliases internally using a hook rather than receiving them as props, removes the related prop from parent components, and adjusts the default "From" address logic. Additional changes include formatting improvements, enhanced logging for alias retrieval on the backend, and a minor update to dialog state handling. Changes
Sequence Diagram(s)sequenceDiagram
participant ParentComponent
participant EmailComposer
participant useEmailAliases (Hook)
participant Backend
ParentComponent->>EmailComposer: Render (no aliases prop)
EmailComposer->>useEmailAliases: Fetch aliases
useEmailAliases->>Backend: Request aliases
Backend-->>useEmailAliases: Return aliases
useEmailAliases-->>EmailComposer: Provide aliases data
EmailComposer->>EmailComposer: Set default "From" address
EmailComposer->>ParentComponent: (On send/close) Notify as before
Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (2)
apps/server/src/lib/driver/google.ts (1)
68-109: 🛠️ Refactor suggestion
⚠️ Potential issueRemove or gate PII–heavy console logging
These new
console.logcalls emit primary and alias email addresses to stdout. In production this ends up in aggregated logs and may violate privacy/SOC 2 controls.Either:
- console.log('Retrieved user profile:', { email: profile.data.emailAddress }); + if (process.env.NODE_ENV === 'development') { + console.debug('[gmail] user profile fetched'); + }or route through your structured logger at a DEBUG level with redaction support.
Same applies to the other log statements in this block.
apps/mail/components/create/email-composer.tsx (1)
170-181: 🛠️ Refactor suggestion
fromEmaildefault never updates after aliases load
defaultValuesis captured once whenuseFormis executed; ifaliasesare still loading,
fromEmailwill be initialised to an empty string and will never auto-populate, forcing
the user to pick a “From” address manually.Add an effect that patches the form as soon as aliases arrive:
+// Auto-select a default "from" once aliases are available +useEffect(() => { + if (!aliases.length) return; + const current = form.getValues('fromEmail'); + if (current) return; // user already touched it + + const fallback = + aliases.find((a) => a.primary)?.email ?? + aliases[0].email; + + form.setValue('fromEmail', fallback, { shouldDirty: false }); +}, [aliases, form]);This guarantees a valid default and keeps UX identical to the previous prop-driven version.
🧹 Nitpick comments (2)
apps/mail/components/create/create-email.tsx (1)
158-160: Consider clearing all compose-related query params on close
handleDialogClosenow resets onlydraftId. For parity with the sidebar’sComposeButton(which nullsto,activeReplyId, andmodeas well), do the same here to avoid stale URL params when the user closes the modal via .if (!open) { await Promise.all([ + setTo(null), + setActiveReplyId(null), + setMode(null), setDraftId(null), ]); }apps/mail/components/create/email-composer.tsx (1)
997-1012: Guard optional chaining in JSX
aliases.lengthis accessed directly inside JSX. Even with the fix above it’s safer and
more idiomatic to rely on optional chaining:-{aliases.length > 0 && ( +{aliases?.length > 0 && (Combined with the normalisation from the first comment, this eliminates
any possibility of rendering-time exceptions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/mail/components/create/create-email.tsx(1 hunks)apps/mail/components/create/email-composer.tsx(5 hunks)apps/mail/components/mail/mail.tsx(2 hunks)apps/mail/components/ui/app-sidebar.tsx(1 hunks)apps/mail/hooks/use-email-aliases.ts(0 hunks)apps/server/src/lib/driver/google.ts(3 hunks)
💤 Files with no reviewable changes (1)
- apps/mail/hooks/use-email-aliases.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/mail/components/mail/mail.tsx (1)
apps/mail/lib/utils.ts (1)
cn(51-51)
🔇 Additional comments (4)
apps/server/src/lib/driver/google.ts (1)
749-754: Mapping refactor looks goodThe switch to a concise arrow-function array map is clearer and keeps the payload small; no functional concerns spotted.
apps/mail/components/ui/app-sidebar.tsx (1)
188-195: Awaiting dialog state before other mutations is sensibleThe added
awaitensures the dialog query param is committed before we clear the rest, preventing flashes in URL state. Looks good.apps/mail/components/mail/mail.tsx (2)
962-972: Minor sizing tweak approvedUsing
categories.findand pre-computingselectedTextLengthimproves readability; width estimates remain heuristic but unchanged in complexity. No issues.
1070-1072: Class-name consolidation OKInlining the
cncall is stylistic; behaviour is unchanged.
| aliases = [], | ||
| editorClassName, | ||
| }: EmailComposerProps) { | ||
| const { data: aliases } = useEmailAliases(); |
There was a problem hiding this comment.
Prevent undefined.length runtime crash by normalizing aliases early
useEmailAliases() may return undefined while the query is still loading.
Any code that blindly dereferences aliases (see 179 and 998) will throw.
-const { data: aliases } = useEmailAliases();
+// Normalise to an empty array so the rest of the component can safely use `.length`
+const { data: aliases = [] } = useEmailAliases();With this guard in place, aliases.length and aliases.map() are always safe.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const { data: aliases } = useEmailAliases(); | |
| // Normalise to an empty array so the rest of the component can safely use `.length` | |
| const { data: aliases = [] } = useEmailAliases(); |
🤖 Prompt for AI Agents
In apps/mail/components/create/email-composer.tsx at line 108, the variable
aliases from useEmailAliases() can be undefined during loading, causing runtime
errors when accessing aliases.length or aliases.map(). To fix this, initialize
aliases to an empty array if it is undefined immediately after the hook call,
ensuring aliases is always an array and safe to use throughout the component.

READ CAREFULLY THEN REMOVE
Remove bullet points that are not relevant.
PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.
Description
Please provide a clear description of your changes.
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Additional Notes
Add any other context about the pull request here.
Screenshots/Recordings
Add screenshots or recordings here if applicable.
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
New Features
Bug Fixes
Chores
Style